package com.ruoyi.informfrontend.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.informfrontend.mapper.ArticleMapper;
import com.ruoyi.informfrontend.domain.Article;
import com.ruoyi.informfrontend.service.IArticleService;

/**
 * 资讯Service业务层处理
 *
 * @author ruoyi
 * @date 2023-05-18
 */
@Service
public class ArticleServiceImpl implements IArticleService
{
    @Autowired
    private ArticleMapper articleMapper;

    /**
     * 查询资讯
     *
     * @param id 资讯主键
     * @return 资讯
     */
    @Override
    public Article selectArticleById(Long id)
    {
        articleMapper.updateNum(id);
        return articleMapper.selectArticleById(id);
    }
    @Override
    public List<Article> selectArticleByIds(Long[] ids)
    {
        List<Article> list = new ArrayList<>();
        for (Long id : ids) {
            articleMapper.updateNum(id);
            list.add(articleMapper.selectArticleById(id));
        }
        return list;
    }

    /**
     * 查询资讯列表
     *
     * @param article 资讯
     * @return 资讯
     */
    @Override
    public List<Article> selectArticleList(Article article)
    {
        return articleMapper.selectArticleList(article);
    }

    /**
     * 新增资讯
     *
     * @param article 资讯
     * @return 结果
     */
    @Override
    public int insertArticle(Article article)
    {
        article.setCreateTime(DateUtils.getNowDate());
        return articleMapper.insertArticle(article);
    }

    /**
     * 修改资讯
     *
     * @param article 资讯
     * @return 结果
     */
    @Override
    public int updateArticle(Article article)
    {
        article.setUpdateTime(DateUtils.getNowDate());
        return articleMapper.updateArticle(article);
    }

    /**
     * 批量删除资讯
     *
     * @param ids 需要删除的资讯主键
     * @return 结果
     */
    @Override
    public int deleteArticleByIds(Long[] ids)
    {
        return articleMapper.deleteArticleByIds(ids);
    }

    /**
     * 删除资讯信息
     *
     * @param id 资讯主键
     * @return 结果
     */
    @Override
    public int deleteArticleById(Long id)
    {
        return articleMapper.deleteArticleById(id);
    }
}
